#include "GLCurve.h"

GLCurve::GLCurve(const std::vector<glm::vec3>& vertices) : GLDraw(), m_vertices(vertices)
{
	GLProgram* program = GLProgram::ShareProgram();

	program->GenerateArray(m_arrayId);
	program->BindArray(m_arrayId);

	// 载入顶点数据
	glBufferData(GL_ARRAY_BUFFER, m_vertices.size() * sizeof(glm::vec3), &m_vertices[0], GL_STATIC_DRAW);

	// vertex Positions
	glEnableVertexAttribArray(0);
	glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(glm::vec3), (void*)0);

	program->UnbindArray();
}

void GLCurve::Draw() const
{
	GLProgram* program = GLProgram::ShareProgram();

	// 开始绘制
	program->BindArray(m_arrayId);
	glDrawArrays(GL_LINE_STRIP, 0, m_vertices.size());

	program->UnbindArray();
}

void GLCurve::Draw(int amount) const
{
	GLProgram* program = GLProgram::ShareProgram();

	// 开始绘制
	program->BindArray(m_arrayId);
	glDrawArraysInstanced(GL_LINE_STRIP, 0, m_vertices.size(), amount);

	program->UnbindArray();
}
